/*
 * @lc app=leetcode.cn id=383 lang=swift
 *
 * [383] 赎金信
 */

// @lc code=start
class Solution {
    func canConstruct(_ ransomNote: String, _ magazine: String) -> Bool {
        if ransomNote.count > magazine.count { return false }
        var counter = [Int](repeating: 0, count: 26)
        let aCharUnicodeScalar = Int("a".unicodeScalars.first!.value)
        for ransom in ransomNote.unicodeScalars {
            counter[Int(ransom.value) - aCharUnicodeScalar] += 1
        }
        for maga in magazine.unicodeScalars {
            counter[Int(maga.value) - aCharUnicodeScalar] -= 1
        }
        guard counter.first(where: { $0 > 0 }) == nil else { return false }
        return true
    }
}
// @lc code=end

